package usecase;

import IBO.IClient;
import IBO.IIntervention;
import IBO.ITechnicien;
import IUSECASE.IUC_GestionOnSite;
import bo.Adresse;
import bo.Client;
import bo.CodePostal;
import bo.Intervention;
import bo.ListeClients;
import bo.ListeInterventions;
import boerrors.AdresseInexistantException;
import boerrors.CodePostalInexistantException;
import boerrors.CodePostalMinimumMultiplicityException;
import boerrors.InterventionInexistantException;
import boerrors.ZoneMinimumMultiplicityException;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.GregorianCalendar;
import java.util.GregorianCalendar;
import java.util.GregorianCalendar;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

public class GestionOnSite extends UnicastRemoteObject implements IUC_GestionOnSite, Serializable {

        private static GestionOnSite instance = null;    
   
        //*******************************************************************    
        //Constructeur du singleton    
        //*******************************************************************        

        public static GestionOnSite getInstance() throws RemoteException {        
                if(instance == null) instance = new GestionOnSite();        
                return instance;    
        }
   
        public GestionOnSite() throws RemoteException {
                super();
        } 

        //*******************************************************************    
        //Methodes heritees    
        //******************************************************************* 

        public Vector<IIntervention> listeIntervention(ITechnicien technicien) throws RemoteException {
                return null;
        }
 
        public void traiter(IIntervention intervention, GregorianCalendar heureDebut) throws RemoteException {
                try {
                    Intervention interventionTampon = ListeInterventions.getInstance().rechercherIntervention(intervention.getIdIntervention());
                    interventionTampon.traiter(heureDebut);
                    bo.ListeInterventions.getInstance().notifyAllSubscibers();
                } catch (InterventionInexistantException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                } catch (AdresseInexistantException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                } catch (CodePostalMinimumMultiplicityException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ZoneMinimumMultiplicityException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                }
        }
    
        public void cloturer(IIntervention intervention, String descriptionIntervention, GregorianCalendar heureFin) throws RemoteException {
                try {
                    Intervention interventionTampon = ListeInterventions.getInstance().rechercherIntervention(intervention.getIdIntervention());
                    interventionTampon.cloturer(descriptionIntervention, heureFin);
                    bo.ListeInterventions.getInstance().notifyAllSubscibers();
                } catch (InterventionInexistantException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                } catch (AdresseInexistantException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                } catch (CodePostalMinimumMultiplicityException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ZoneMinimumMultiplicityException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                }
        }
    
        public void annuler(IIntervention intervention) throws RemoteException {
                try {
                    Intervention interventionTampon = ListeInterventions.getInstance().rechercherIntervention(intervention.getIdIntervention());
                    interventionTampon.annuler();
                    bo.ListeInterventions.getInstance().notifyAllSubscibers();
                } catch (InterventionInexistantException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                } catch (AdresseInexistantException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                } catch (CodePostalMinimumMultiplicityException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ZoneMinimumMultiplicityException ex) {
                    Logger.getLogger(GestionOnSite.class.getName()).log(Level.SEVERE, null, ex);
                }
        }
        // suivi
        public void creerSousIntervention( IIntervention intervention, String descriptionIntervention, GregorianCalendar heureFin,
                                                    String descriptionDemande, String degre) 
                                                    throws RemoteException {
                
                        Intervention intTmp = bo.ListeInterventions.getInstance().rechercherIntervention(intervention.getIdIntervention());  
                        intTmp.setDescriptionIntervention(descriptionIntervention);
                        intTmp.setHeureFin(heureFin);
                        new Intervention(intTmp, descriptionDemande, degre);                                              
                
        }

    public IIntervention creerSousIntervention(IClient client, String degre, String description, String rue, String numero, String[] codePostal, GregorianCalendar dateDemande) throws RemoteException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
